<template>
  <div class="body">
    <header class="header">
      <div class="title">
        <img src="../../../assets/images/01_11.png" alt="" class="img_zuo" @click="back" />
        <div>巡查排查</div>
      </div>
    </header>
    <div class="contant">
      <!--<van-pull-refresh v-model="refreshing" @refresh="onRefresh">-->
      <van-list v-model="loading" :finished="finished" :finished-text="finishedText" @load="onLoads()">
        <div @click="btn(item)" class="box_list" v-for="(item, index) in datas" :key="index">
          <img class="img_logo5" src="../../../assets/images/logo5.png" />
          <div class="center">
            <div style="width: 70%;">
              <div class="small_title">[{{item.broadHeadingName}}]{{item.unitsName ? item.unitsName : '无对象'}}</div>
              <div class="introduce">
                <!-- <div>{{item.phcName}}</div> -->
                <div class="intro_name">
                  <div v-if="item.yhlb === 100 || item.yhlb === 102">
                    <img style="width: 13px" data-id="1"
                      :src="item.isRectifica === 1 || item.isRectifica === 3 || item.isRectifica === 6 ? isRectificas : isRectifica" />
                  </div>
                  <div v-else>
                    <div v-if="item.hasOwnProperty('isRectifica')">
                      <img v-if="item.isRectifica !== -1  && item.isRectifica !== 0 " style="width: 13px"
                        :src="isRectificas" data-id="2">
                    </div>
                    <div v-else>
                      <img v-if="(item.yhlb === 1 || item.yhlb === 2) && item.status != 0" style="width: 13px;"
                        :src="isRectificas" data-id="3">
                      <div v-else>
                        <img v-if="item.yhlb === 1 || item.yhlb === 2" style="width: 13px" :src="isRectifica"
                          data-id="4">
                      </div>
                    </div>
                  </div>
                  <img src="../../../assets/images/people.png" />
                  <div>{{item.ptPerson}}</div>
                </div>
              </div>
            </div>
            <div class="data">{{item.niAddtime}}</div>
          </div>
        </div>
      </van-list>
      <!--</van-pull-refresh>-->
      <!-- <div class="box_list">
        <img class="img_logo5" src="../../../assets/images/logo5.png" />
        <div class="center">
          <div class="small_title">[小餐馆]抽油烟机、排放</div>
          <div class="introduce">
            <div>随查即改</div>
            <div class="intro_name">
              <img src="../../../assets/images/people.png" />
              <div>张珊珊</div>
            </div>
          </div>
        </div>
        <div class="data">5-20</div>
      </div> -->

    </div>

    <div class="triangle" v-show="show"></div>
    <div class="xz_conter" v-show="show">
      <div @click="scan">扫一扫</div>
      <div @click="jump">新增</div>
    </div>

  </div>
</template>

<script>
  export default {
    name: 'community_list_rwjb',
    data() {
      return {
        isRectifica: require('../../../assets/images/jsd.gif'),
        isRectificas: require('../../../assets/images/lg.png'),
        title: null,
        show: false,//显示隐藏增加栏
        userId: null,//用户id
        shequ_id: 23,//社区ID
        datas: [],
        listId: 0,
        active: 0,
        icon: {
          active: require('../../../assets/images/tabbar_home_active.png'),
          inactive: require('../../../assets/images/tabbar_home.png')
        },
        icon2: {
          active: require('../../../assets/images/tabbar_msg_active.png'),
          inactive: require('../../../assets/images/tabbar_msg.png')
        },
        icon3: {
          active: require('../../../assets/images/call_active.png'),
          inactive: require('../../../assets/images/call.png')
        },
        icon4: {
          active: require('../../../assets/images/tabbar_user_active.png'),
          inactive: require('../../../assets/images/tabbar_user.png')
        },
        taskSpecialId: null,//具体任务id
        theNewTaskAssignId: null,//专项任务id
        rwjbDwType: null,//单位类型 0接收，1发文
        loading: false,
        finished: false,
        refreshing: false,
        total: 1,
        pageInfo: {
          page: 1,
          pageSize: 20
        },
        load_over: false,
        finishedText: ''
      }
    },
    beforeRouteLeave(to, from, next) {
      //设置路由的 meta
      if (!(to.path == '/hard_detail')) {
        localStorage.removeItem("list_scrollTops");
      }
      next();
    },
    //进入该页面时，用之前保存的滚动位置赋值
    beforeRouteEnter(to, from, next) {
      next(vm => {
        var list_scrollTops = localStorage.getItem("list_scrollTops");
        console.log(localStorage.getItem("list_scrollTops"))
        if (list_scrollTops !== null) {
          $('.contant').animate({ scrollTop: list_scrollTops }, 0);
        } else {
          vm.userId = localStorage.getItem("userId")//获取访问id
          vm.taskSpecialId = localStorage.getItem("rwjb_taskSpecialId");
          vm.theNewTaskAssignId = localStorage.getItem("rwjb_theNewTaskAssignId");
          vm.rwjbDwType = localStorage.getItem("rwjbDwType");
          vm.listId = Number(localStorage.getItem("listId"));
          if (vm.load_over) {

          }
          console.log(vm.datas.length)
          vm.refreshing = true;
          vm.datas = [];
          vm.total = 1;
          vm.pageInfo.page = 1;
          if (vm.datas.length === 0) {
            vm.onLoad()
          }
        }
        // console.log(this.listId)
        localStorage.removeItem("list_scrollTops");
      })
    },
    methods: {
      onLoads() {
        if (this.datas.length > 0) {
          this.onLoad()
        }
      },
      //  分页加载
      onLoad() {
        var _this = this;
        setTimeout(() => {
          if (_this.refreshing) {
            _this.datas = [];
            _this.refreshing = false;
          }
          if (_this.datas.length !== _this.total) {
            this.finished = false;
            _this.pdQuery();
          } else {
            if (_this.total <= 15) {
              _this.finishedText = '';
            } else {
              this.finishedText = '没有更多啦';
            }
            _this.finished = true;
          }
        }, 1000);
      },
      //  下拉加载
      // onRefresh() {
      //   this.finished = true;
      //   this.loading = true;
      //   this.pageInfo.page = 1;
      //   this.onLoad();
      // },
      back() {
        // let a = sessionStorage.getItem('pdId');
        // if (a) {
        //   if (a === '1') {
        //     this.$router.push("/jzw_see");
        //   } else if (a === '2') {
        //     this.$router.push("/jxmd_see");
        //   } else if (a === '3') {
        //     this.$router.push("/zgf_see");
        //   }
        // } else {
        //   this.$router.push("/table_list");
        // }
        // sessionStorage.removeItem('pdId')
        this.$router.back()
      },
      jump() {
        localStorage.removeItem("xcpc_da_obj");
        //this.$router.push("/xcpc_add");
      },
      btn(data) {
        console.log(data)
        sessionStorage.setItem("inspection_patrolTroubleshootId", data.patrolTroubleshootId)
        sessionStorage.setItem("inspection_infoId", data.patrolTroubleshootInfoId)
        localStorage.setItem("hard_detail_from", '/community_list_rwjb');
        localStorage.setItem("list_scrollTops", $('.contant').scrollTop());

        if (data.patrolTroubleshootId !== 0) {
          console.log(99999999)
          console.log(data.patrol_troubleshoot)
          this.$router.push("/hard_detail");
        } else if (data.patrolTroubleshootId == 0) {
          this.$router.push({
            path: '/ptlook',
            query: { id: data.noweInfoId, ids: 14 }
          });
        }
      },
      add() {
        this.show ? this.show = false : this.show = true
      },
      scan() {
        // this.show=false
        sessionStorage.removeItem('qujiname');
        sessionStorage.removeItem('jiedaoname');
        sessionStorage.removeItem('shequname');
        sessionStorage.removeItem('number');
        sessionStorage.removeItem('yeschuan');
        sessionStorage.removeItem('str');
        sessionStorage.removeItem('fidname');
        sessionStorage.removeItem('didname');
        localStorage.removeItem("xcpc_da_obj");
        this.$router.push("/xcpc_scan");
      },
      // inspection(id, cunt) {
      //   // alert(id)
      //   if (cunt != 0) {
      //     this.$router.push("/inspection");
      //     sessionStorage.setItem("jzw_community_list_shequ_id", id)
      //   }
      // },
      inof() {
        var _this = this;
        /*try {
          plus.nativeUI.showWaiting("正在加载...");
        } catch (e) {
          console.log('plus问题');
        }*/
        var params = {
          taskSpecialId: _this.taskSpecialId,//具体任务id
          theNewTaskAssignId: _this.theNewTaskAssignId,//专项任务id
          isPostOrGet: _this.rwjbDwType,
          userId: _this.userId,
          pageRows: _this.pageInfo.page,
          pageSize: _this.pageInfo.pageSize,
        };
        _this.axios.get(_this.$global_msg.Url.host + "/taskAssign/xunchaList", {
          params: params
        }).then(function (data) {
          try {
            plus.nativeUI.closeWaiting();
          } catch (e) {
            console.log(e.message);
          }
          if (data && data.data) {
            if (data.data.code == 200) {
              _this.loading = false;
              _this.datas = _this.datas.concat(data.data.rows);
              _this.total = data.data.total;
              _this.pageInfo.page++;
            } else {
              _this.$toast(data.data.msg);
            }
            _this.load_over = true;
          } else {
            _this.$toast('查询失败');
          }
        }).catch(error => {
          this.$terminal._error(error)
        });
      },
      query(router) {
        var that = this;
        /*try {
          plus.nativeUI.showWaiting("正在加载...");
        } catch (e) {
          console.log('plus问题');
        }*/
        console.log(that.userId)
        // console.log(that.listId)
        var params = {
          id: that.listId,//具体任务id
          page: that.pageInfo.page,
          pageSize: that.pageInfo.pageSize,
          type: 0
        };
        that.axios.get(`${that.$global_msg.Url.host}/${router}/selectNoweInfo`,
          { params }).then(res => {
            console.log(res)
            if (res.data.code === 0) {
              that.loading = false;
              that.datas = that.datas.concat(res.data.rows);
              that.total = res.data.total;
              that.pageInfo.page++;
            } else {
              that.$toast(res.data.msg);
            }
            that.load_over = true;
            try {
              plus.nativeUI.closeWaiting();
            } catch (e) {
              console.log(e.message);
            }
          }).catch(error => {
            this.$terminal._error(error)
          });
      },
      pdQuery() {
        let that = this;
        let a = sessionStorage.getItem('pdId');
        if (a) {
          if (a === '1') {
            that.query('construction');
          } else if (a === '2') {
            that.query('nineStore');
          } else if (a === '3') {
            that.query('zgfinfo')
          } else if (a === '4') {
            that.query('enterprise')
          }
        } else {
          that.inof();
        }
      }
    },
    beforeRouteLeave(to, from, next) {
      sessionStorage.removeItem('pdId')
      next();
    },
    created() {
      var _this = this;
      //物理返回
      // window.addEventListener("popstate", function(){
      //   _this.back();
      // }, false);
    }
  }
</script>

<style scoped>
  .body {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
  }

  /* .van-pull-refresh {
    height: 100%;
    min-height: calc(100vh - 1.8519rem);
  } */
  /* 头部 */
  .header {
    height: 1.8519rem;
    background: #007aff;
    padding-top: 0.8333rem;
    box-sizing: border-box;
    width: 100%;
    z-index: 20;
    font-size: 0.388888rem;
  }

  .title {
    padding: 0 0.3704rem;
    display: flex;
    align-items: center;
    color: #fff;
  }

  .title>div {
    width: 100%;
    font-size: 0.4444rem;
    text-align: center;
  }

  .img_zuo {
    width: 0.2593rem;
    height: 0.463rem;
  }

  .img_jia {
    width: 0.629629rem;
    height: 0.629629rem;
    position: absolute;
    right: 0.3704rem;
  }





  /* 弹框 */

  .yc {
    display: none;
  }

  .triangle {
    width: 0;
    height: 0;
    border-left: 0.2222rem solid transparent;
    border-right: 0.2222rem solid transparent;
    border-bottom: 0.4444rem solid #686868;
    position: fixed;
    top: 1.4815rem;
    right: 0.3704rem;
    z-index: 21;
  }

  .xz_conter {
    width: 1.8519rem;
    border-radius: 0.1852rem;
    padding: 0 0.1111rem;
    background: #686868;
    position: fixed;
    top: 1.8519rem;
    right: 0.0926rem;
    color: #fff;
    font-size: 0.3889rem;
  }

  .xz_conter>div {
    font-size: 0.3519rem;
    padding: 0.2222rem 0.0926rem;
    border-bottom: 1Px solid #888888;

  }



  /* 底部导航 */
  .van-tabbar {
    padding: 0.4rem 0;
  }

  .van-tabbar--fixed {
    position: fixed;
    bottom: 0;
    left: 0;
    background: #ffffff;
  }

  .van-tabbar--fixed {
    border-top: 1px solid #cccccc;
    /* border: none; */
    padding-top: 0.8rem;
  }

  .van-tabbar-item {
    font-size: 0.44rem;
    line-height: 0.6rem;
  }

  .van-tabbar-item__icon img {
    display: block;
    height: 0.5333rem;
  }

  [class*=van-hairline]::after {
    border: none;
  }

  /* 主体 */

  .img_logo5 {
    width: 0.6667rem;
    height: 0.7407rem;
    margin: 0 0.2778rem;
    margin-right: 0.5556rem;
  }

  .data {
    color: #8E8E8E;
  }

  .center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 0.2778rem;
    padding-top: 0.1852rem;
  }

  .intro_name {
    display: flex;
    align-items: center;
    /* margin-left: 0.5rem; */
  }

  .intro_name img {
    width: 0.2963rem;
    margin-right: 0.1852rem;
  }

  .intro_name div {
    font-size: 0.2963rem;
  }

  .introduce {
    display: flex;
    color: #8E8E8E;
    font-size: 0.3148rem;
    align-items: center;
    margin-top: 0.0926rem;
  }

  .small_title {
    width: 5.6481rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .box_list {
    /* border-bottom: 1Px solid #ddd; */
    display: flex;
    align-items: center;
    height: 1.3889rem;
  }

  .img_big {
    width: 0.629629rem;
    height: 0.629629rem;
  }

  .contant {
    width: 100%;
    flex: 1;
    overflow-y: scroll;
  }
</style>